package org.example.SlApi;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.example.JycInfo;
import org.example.utils.ReadConf;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import java.util.List;
import java.util.Map;

import static org.example.CookieHandlingFilter.cookies;
import static org.example.RestClient.givenWithCookies;
import static org.example.RestClient.loginAndUpdateCookies;
import static org.example.SlApi.JbxxApi.QyjbxxbcApi.initJyclist;

public class DqqyApi {

    public static Map<String, String> loginAndUpdateCookies;


    public static void main(String[] args) throws IOException {    //企业开办
        McccApi();
    }

    public static int McccApi() throws IOException {
        // 登录并更新cookies

        loginAndUpdateCookies();

        RestAssured.baseURI = ReadConf.getHost(); // 设置基础URI
        List<JycInfo> jycInfoList = initJyclist(); // 调用方法来获取列表
        if (!jycInfoList.isEmpty()) {
            JycInfo firstJycInfo = jycInfoList.get(0); // 获取列表中的第一个元素
            String sbid = firstJycInfo.getSbid();
            String nameid = firstJycInfo.getName_id(); // 使用实际的getter方法

            String data = "ywtSldj.do?method=editZssblr&sbid="+ sbid +"&name_id="+nameid+"&pripid=&ljmsign=2&csrftoken=";
            Response response = givenWithCookies()


//               .cookies(cookies)


                    .get(data); // 注意：可能需要有效的 CSRF Token
            System.out.println(cookies);
            int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
            System.out.println(statusCode);
            String body = response.getBody().asString();
            System.out.println(body);


            return statusCode;
        }

        return 0;
    }
}